const express = require('express')
const router = express.Router()
const multer = require('multer')

/**
 * 图片上传
 */
const storage = multer.diskStorage({
    // 保存路径
    destination: '../public/images/century_restaurant',
    filename: (req, file, cb) => {
        const fileFormat = file.originalname.split(".")
        // 拼接文件名
        cb(null, `${new Date().getTime()}.${fileFormat[fileFormat.length - 1]}`)
    }
})

const uploadRoutes = multer({
    storage
})

// 上传文件控制器
const uploadController = require('../controllers/uploadController.js')

// 上传文件接口
router.post('/files', uploadRoutes.single('file'), uploadController.uploadFiles)

module.exports = router
